home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / mail / YAMscripts.lha / CheckNewMail.rexx < prev    next >
OS/2 REXX Batch file  |  1997-06-17  |  4KB  |  147 lines

  1. /*                      CheckNewMail.rexx
  2.             v 1.5 - 11-Jun-97
  3.  
  4.    This script checks if there are new or unread messages and where they are.
  5.    It requiress reqtools and rexxreqtools libraries.
  6.  
  7.    Changes in 1.5
  8.     - If the value of variable AllowDupl is 'no' then only one instance
  9.       of the script can be running any given time.  If the script is
  10.       started while the requester is still open, it quits.
  11.  
  12.    Changes in 1.4
  13.     - Doesn't get confused if some folders have been deleted
  14.  
  15.    This and more than dozen other scripts can be found at
  16.    http://www.utu.fi/~knikulai/ARexx.html
  17.  
  18.    You can also get the latest version of this script by sending a message
  19.    with subject REQUEST to knikulai@utu.fi.  In the message body you can
  20.    use commands dir, get <file> and help.
  21. */
  22. call addlib('rexxsupport.library',0,-30,0)
  23. options results
  24. AllowDupl='no'    /* If set to 'no', the script quits if the requester is already open */
  25. maxfolder=12    /* Set this to the number of folders you have-1*/
  26. cols=3        /* How many colums of folders in requester */
  27. wid=17        /* Max displayed width of foldername + message counts*/
  28. butl=70        /* Maximum length of buttons in characters. Increase this a bit
  29.                    if you are using a proportional font. */
  30. dontquit='OFF'  /* If 'on', the requester stays until Done is selected*/
  31. sunr='YES'    /* Search for unread messages too ( yes/no ) */
  32.  
  33. /* Change these to something you like */
  34.           title='CheckNewMail.rexx' 
  35.       new_title='You have new mail in following folders: (new/unread)' 
  36.    no_new_title='You have no new mail.'
  37.    unread_title='You have unread mail in following folders:' 
  38. no_unread_title='You have no folders with only unread mail.'
  39.   select_folder='Select folder you want to read next'
  40.     last_button='_Done'
  41.  
  42. if upper(AllowDupl)='NO' & show('p','CNMport') then exit
  43. call OpenPort('CNMport')
  44.  
  45. addlib('rexxreqtools.library',0,-30)
  46. address 'YAM' 
  47. 'Hide'
  48.  
  49. GetFolderInfo Number    /* Let's remember where we are now */
  50. orig_fold=result
  51. GetMailInfo Active
  52. orig_msg=result
  53.  
  54. nc=0        /* new-counter */
  55. uc=0        /* unread-counter */
  56. NL='0a'x    /* newline */
  57. do f=0 to maxfolder
  58.    if f~=1 & f~=2 then do  /* Don't check Outgoing nor Sent */
  59.         SetFolder f
  60.     if rc=0 then do
  61.          GetFolderInfo Name
  62.         fn=result        /* Name of the folder */
  63.         GetFolderInfo Max
  64.         n=result        /* Number of messages in the folder */
  65.         i=0
  66.         nm=0
  67.         um=0
  68.         do while i<n
  69.            SetMail i
  70.            i=i+1
  71.            GetMailInfo Status
  72.            if result='N' then nm=nm+1    /* New message was found */
  73.            if result='U' & upper(sunr)='YES' then um=um+1/* Unread message was found */
  74.         end /* do while i<n */
  75.         if nm>0 then do  /* New messages were found */
  76.            nc=nc+1
  77.            foo= nm ||'/'|| um 
  78.            new.nc=left(fn||' ',wid-length(foo), '.') || foo
  79.            newn.nc=f
  80.            end
  81.         else
  82.         if um>0 & upper(sunr)='YES' then do  /* New messages were found */
  83.            uc=uc+1       
  84.            unread.uc=left(fn||' ', wid-length(um), '.') || um
  85.            unreadn.uc=f
  86.            end
  87.     end /* if rc=0 */
  88.     
  89.     end /* if f~=1 & f`=2 then do */    
  90. end /* do f=0 to maxfolder */
  91.  
  92. /* Now all folders have been scanned */
  93. but=''
  94. bc=0
  95.  
  96. /* Return to where we were before starting this script */
  97. 'Show'
  98. 'SetFolder' orig_fold
  99. 'SetMail' orig_msg
  100.  
  101. /* Let's first list new messages */
  102. if nc>0 then 
  103.       rt=new_title
  104. else 
  105.       rt=no_new_title || NL
  106.  
  107. rt=rt || NL
  108. do i=1 to nc
  109.     rt=rt || new.i || '  '
  110.     if length(but)+length(word(new.i,1))<butl then do 
  111.         but=but || word(new.i,1) || '|'
  112.         bc=bc+1
  113.         butn.bc=newn.i
  114.         end
  115.     if i//cols = 0 then rt=rt || NL
  116. end
  117.  
  118. /* Then it's time to list unread messages, if that was asked */
  119. if upper(sunr)='YES' then do
  120.     if uc>0 then 
  121.         rt=rt||NL|| unread_title
  122.     else 
  123.         rt=rt||NL|| no_unread_title
  124.     rt=rt || NL
  125.     do i=1 to uc
  126.         rt=rt || unread.i ||'  '
  127.         if i//cols = 0 then rt=rt || NL
  128.         if length(but)+length(word(unread.i,1))<butl then do
  129.             but=but || word(unread.i,1) || '|'
  130.             bc=bc+1
  131.             butn.bc=unreadn.i
  132.             end
  133.     end
  134. end /* if upper(sunr)='YES' */
  135.  
  136. rt=rt || NL || NL || select_folder
  137. but=but || last_button
  138. tags='rtez_defaultresponse=0'
  139.  
  140. sel=1
  141.  
  142.  
  143. do until sel=0 | upper(dontquit)='OFF'
  144.    sel=rtezrequest(rt,but,title,tags)
  145.    if sel>0 then address 'YAM' 'SetFolder ' || butn.sel
  146. end
  147.